<template>
    <h2>添加房号表</h2>
    <table border="1">
        <tr>
            <td>房号名称</td>
            <td>
                <input type="text" v-model="info.Rnumber_Name">
            </td>
        </tr>
        <tr>
            <td>楼层</td>
            <td>
                <input type="number" v-model="info.Rnumber_Floor">
            </td>
        </tr>
        <tr>
            <td>具体房间号</td>
            <td>
                <input type="text" v-model="info.Rnumber_Num">
            </td>
        </tr>
        <tr>
            <td>房号状态</td>
            <td>
                <input type="radio" :value="true" v-model="info.Rnumber_State">空房可住
                <input type="radio" :value="false" v-model="info.Rnumber_State">已有入住
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="保存" @click="SaveData">
            </td>
        </tr>
       
    </table>
    
    </template>
<script setup lang="ts">

import axios from "axios";
import { onMounted ,ref} from "vue";
import { useRoute,useRouter } from "vue-router";

const route=useRoute();
const router=useRouter();


onMounted(()=>{
    LoadData();
})


const LoadData=()=>{

    axios.get('https://localhost:7153/api/T_RoomNumber/GetNumber',
    
    {
        params:{
            RnumberId:route.params.id
        }
    }
    )

    .then(res=>{
        info.value=res.data
    })


}

const info=ref({
 
 Rnumber_Name: "",
 Rnumber_Floor: "",
 Rnumber_Num: "",
 Rnumber_State: true,
 


})




const SaveData=()=>{

if(info.value.Rnumber_Name==""){
    alert("房号表名称不能为空");
    return;
}

axios.put('https://localhost:7153/api/T_RoomNumber/UpdateNumber',info.value)
.then(res=>{
     if(res.data>0){
        alert("修改成功");
        router.push("/ShowRoomNumber")
        
    }
    else{
        alert("修改失败");
    }


})


}


</script>